#include "../common/global.h"
#include "renderer.h"

rd_globals_t rd;

void rd_show_all(void)
{
	if (SDL_Flip(rd.screen) == -1)
		com_fatal("SDL_Flip");
}

void rd_toggle_fullscreen(void)
{
	rd.fullscreen = !rd.fullscreen;

	rd.screen = SDL_SetVideoMode(screen_width, screen_height, 0,
			SDL_HWSURFACE|SDL_DOUBLEBUF|(rd.fullscreen * SDL_FULLSCREEN));
	if (rd.screen == NULL)
		com_fatal("SDL_SetVideoMode:toggle fullscreen");
}

void init_renderer(void)
{
	com_memset(&rd, 0, sizeof(rd));

	rd.screen = SDL_SetVideoMode(screen_width, screen_height, 0,
			SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
	if (rd.screen == NULL)
		com_fatal("SDL_SetVideoMode:init");
	rd.fullscreen = true;
	SDL_ShowCursor(SDL_DISABLE);

	rd.camera.w = screen_width;
	rd.camera.h = screen_height;

	rd_load_map("default");

	rd.cursor_img = rd_load_surface("../data/image/cursor.png");
	rd.sight_mask = rd_load_surface("../data/image/sight_mask.png");
	rd.shadow = rd_load_surface("../data/image/shadow.png");
	if (rd.cursor_img && rd.sight_mask && rd.shadow == NULL) {
		com_fatal("fail to load image!!!");
	}
}

void release_renderer(void)
{
	;
}

